package demo.ht.com.basequickadpater.activitys;

import androidx.appcompat.app.AppCompatActivity;

import demo.ht.com.basequickadpater.R;
import demo.ht.com.basequickadpater.utils.CRC16Utli;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

/**
 * @ClassName ItemBean
 * 作者: szj
 * 时间: 2021/1/18 10:57
 * CSDN:https://blog.csdn.net/weixin_44819566
 * 公众号:码上变有钱
 */
public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button bt1 = findViewById(R.id.bt1);
        Button bt2 = findViewById(R.id.bt2);
        Button bt3 = findViewById(R.id.bt3);
        Button bt4 = findViewById(R.id.bt4);
        Button bt5 = findViewById(R.id.bt5);
        Button bt6 = findViewById(R.id.bt6);
        Button bt7 = findViewById(R.id.bt7);
        Button bt8 = findViewById(R.id.bt8);
        Button bt9 = findViewById(R.id.bt9);

        /*
         * 普通布局
         */
        bt1.setOnClickListener(v -> ToActivity(OrdinaryActivity.class));

        /*
         * 双布局
         */
        bt2.setOnClickListener(v -> ToActivity(SectionActivity.class));

        /*
         * 多布局
         */
        bt3.setOnClickListener(v -> ToActivity(MultiActivity.class));

        /*
         * 拖拽布局
         */
        bt4.setOnClickListener(v -> ToActivity(RemoveActivity.class));

        /*
         * 三级列表
         */
        bt5.setOnClickListener(v -> ToActivity(ExpandActivity.class));

        /*
         * 百分比布局
         */
        bt6.setOnClickListener(v -> ToActivity(PercentActivity.class));

        /*
         * DataBinding
         */
        bt7.setOnClickListener(v -> ToActivity(BinActivity.class));

        //内存泄露
        bt8.setOnClickListener(v -> ToActivity(LeakCanaryActivity.class));

        //开机动画
        bt9.setOnClickListener(v -> ToActivity(AnimationActivity.class));
    }


    //跳转页面
    private void ToActivity(Class<?> activityClass) {
        if (isFastClick()) {
            startActivity(new Intent(MainActivity.this, activityClass));
        }
    }

    // 两次点击间隔不能少于1000ms
    private static final int FAST_CLICK_DELAY_TIME = 1000;
    private static long lastClickTime;

    public static boolean isFastClick() {
        boolean flag = false;
        long currentClickTime = System.currentTimeMillis();
        if ((currentClickTime - lastClickTime) >= FAST_CLICK_DELAY_TIME) {
            flag = true;
        }
        lastClickTime = currentClickTime;
        return flag;
    }


    public void onImageClick(View view) {
        ToActivity(ImageActivity.class);
    }

    public void onTouchEventViewClick(View view) {
        ToActivity(TouchEventActivity.class);
    }

    public void onTextImageClick(View view) {
        ToActivity(TextImageActivity.class);
    }
}